<?php
namespace Tbf\Component\BarCode;
class BarCodeRequest {
    /**
     * Image type
     */
    const IMAGE_PNG     = 'png';
    const IMAGE_GIF     = 'gif';
    const IMAGE_JPEG    = 'jpg';

    /**
     * Barcode type
     */
    const BARCODE_CODE39    = 'code39';
    const BARCODE_INT25     = 'int25';
    const BARCODE_EAN13     = 'ean13';
    const BARCODE_UPCA      = 'upca';
    const BARCODE_UPCE      = 'upce';
    const BARCODE_CODE128   = 'code128';
    const BARCODE_EAN8      = 'ean8';
    const BARCODE_POSTNET   = 'postnet';
    const BARCODE_QR        = 'qr';

    /**
     * Rotation type
     */
    const ROTATE_NONE     = 0;
    const ROTATE_RIGHT    = 90;
    const ROTATE_UTURN    = 180;
    const ROTATE_LEFT     = 270;

    /**
     * qr code eclevel
     */
    const QR_ECLEVEL_L = 0;
    const QR_ECLEVEL_M = 1;
    const QR_ECLEVEL_Q = 2;
    const QR_ECLEVEL_H = 3;

    /**
     * output type
     */
    const OUTPUT_TYPE_FILE = 'file';
    const OUTPUT_TYPE_ECHO = 'echo';
    const OUTPUT_TYPE_STRING = 'string';
    const OUTPUT_TYPE_MEMORY_BLOB = 'memory_blob';
    const OUTPUT_TYPE_GD_IMAGE = 'gd_image';

    protected $text;
    protected $img_type = BarCodeRequest::IMAGE_PNG;
    protected $type;
    protected $output_type = BarCodeRequest::OUTPUT_TYPE_FILE;
    protected $save_file_path;
    protected $linear_height=60;
    protected $linear_width=1;
    protected $linear_show_text = true;
    protected $linear_rotate = BarCodeRequest::ROTATE_NONE;
    protected $qr_eclevel = BarCodeRequest::QR_ECLEVEL_H;
    protected $qr_size = 3;
    protected $qr_margin = 0;

    /**
     * @param string $img_type
     */
    public function setImgType($img_type)
    {
        $this->img_type = $img_type;
        return $this;
    }

    /**
     * @return string
     */
    public function getImgType()
    {
        return $this->img_type;
    }

    /**
     * @param int $linear_height
     */
    public function setLinearHeight($linear_height)
    {
        $this->linear_height = $linear_height;
        return $this;
    }

    /**
     * @return int
     */
    public function getLinearHeight()
    {
        return $this->linear_height;
    }

    /**
     * @param int $linear_rotate
     */
    public function setLinearRotate($linear_rotate)
    {
        $this->linear_rotate = $linear_rotate;
        return $this;
    }

    /**
     * @return int
     */
    public function getLinearRotate()
    {
        return $this->linear_rotate;
    }

    /**
     * @param boolean $linear_show_text
     */
    public function setLinearShowText($linear_show_text)
    {
        $this->linear_show_text = $linear_show_text;
        return $this;
    }

    /**
     * @return boolean
     */
    public function getLinearShowText()
    {
        return $this->linear_show_text;
    }

    /**
     * @param int $linear_width
     */
    public function setLinearWidth($linear_width)
    {
        $this->linear_width = $linear_width;
        return $this;
    }

    /**
     * @return int
     */
    public function getLinearWidth()
    {
        return $this->linear_width;
    }

    /**
     * @param mixed $output_type
     */
    public function setOutputType($output_type)
    {
        $this->output_type = $output_type;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getOutputType()
    {
        return $this->output_type;
    }

    /**
     * @param int $qr_eclevel
     */
    public function setQrEclevel($qr_eclevel)
    {
        $this->qr_eclevel = $qr_eclevel;
        return $this;
    }

    /**
     * @return int
     */
    public function getQrEclevel()
    {
        return $this->qr_eclevel;
    }

    /**
     * @param int $qr_margin
     */
    public function setQrMargin($qr_margin)
    {
        $this->qr_margin = $qr_margin;
        return $this;
    }

    /**
     * @return int
     */
    public function getQrMargin()
    {
        return $this->qr_margin;
    }

    /**
     * @param int $qr_size
     */
    public function setQrSize($qr_size)
    {
        $this->qr_size = $qr_size;
        return $this;
    }

    /**
     * @return int
     */
    public function getQrSize()
    {
        return $this->qr_size;
    }

    /**
     * 设置保存路径
     * 自动设置输出方式为文件
     * @param mixed $save_file_path
     */
    public function setSaveFilePath($save_file_path)
    {
        $this->save_file_path = $save_file_path;
        $this->output_type = BarCodeRequest::OUTPUT_TYPE_FILE;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getSaveFilePath()
    {
        return $this->save_file_path;
    }

    /**
     * @param mixed $text
     */
    public function setText($text)
    {
        $this->text = $text;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getText()
    {
        return $this->text;
    }

    /**
     * @param mixed $type
     */
    public function setType($type)
    {
        $this->type = $type;
        return $this;
    }

    /**
     * @return mixed
     */
    public function getType()
    {
        return $this->type;
    }

    public function setOutputGdImage(){
        $this->setOutputType(BarCodeRequest::OUTPUT_TYPE_GD_IMAGE);
        return $this;
    }
    /**
     *
     * 仅做方便快捷用
     * @return null|string
     */
    public function draw(){
        return BarCodeFunction::draw($this);
    }

    public function setTypeQr(){
        $this->type = BarCodeRequest::BARCODE_QR;
        return $this;
    }
    public function setTypeCode128(){
        $this->type = BarCodeRequest::BARCODE_CODE128;
        return $this;
    }
    public function setTypeEan13(){
        $this->type = BarCodeRequest::BARCODE_EAN13;
        return $this;
    }
}